<?php
class Zen_View_Helper_Info_Table extends Zend_View_Helper_Abstract 
{
	public function info_Table($model, $attribs = null)  {
		$xhtml = '';
		if (! $model)
			return $xhtml;
		$table_name = $model->getTableName();
		$model = new Zen_List($table_name);
		$xhtml .= '<div style="width: 500px;"><br/><br/><span class="label label-info">Дополнительная информация:</span><br/><br/>';
		$xhtml .= '<table class="table statistic-table">';
		$expression = "count(1)  as `length`";
		$res = $model->select()->setColumns(array(new Zend_Db_Expr ( $expression )))->getOne();
		if ($res) {
			$xhtml .="<tr><td><i class='icon-align-justify'></i> Всего записей:</td><td style='text-align: right'><span class='badge badge-warning'>" . $res['length'] . "</span></td></tr>";
		}
		try {
			$res = $model->select()->setColumns(array(new Zend_Db_Expr ( $expression )))->getOne("active=1");
			$xhtml .="<tr><td><i class='icon-list'></i> Активных записей:</td><td style='text-align: right'> <span class='badge badge-success'>" . $res['length'] . "</span></td></tr>";
		}catch (Exception $e){}
		$model = new Log_Model_Message();
		$info = $model->getInfoByResource($table_name);
		if ($info){
			$xhtml .="<tr><td><i class='icon-user'></i> Последние изменения произведены пользователем:</td><td style='text-align: right'> <span class='badge badge-important'>" . $info['username'] . "</span></td></tr>";
			$xhtml .="<tr><td><i class='icon-time'></i> Время последних изменений:</td><td style='text-align: right'> <span class='badge'>" . $info['timestamp'] . "</span></td></tr>";
		}
		$xhtml .= '</table>';
		$xhtml .= '</div>';
		return  $xhtml;
	}
	
} 